package collectionUnSafe.list;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

public class ListTestSafe3 {
    public static void main(String[] args) {
        //CopyOnWrite：写入时复制 避免覆盖
        List<String> list = new CopyOnWriteArrayList<>();

        for(int i = 0 ; i < 10 ; i++){
            new Thread(()->{
                list.add(UUID.randomUUID().toString().substring(0,5));
                System.out.println(list);
            },"线程"+i).start();
        }

        // ConcurrentModificationException:并发修改异常
    }
}
